# -*- coding: utf-8 -*-
# @Time : 2025-05-21 15:22
# @File : 数据可视化_pandas_matlpotlib_excel
# @Software: VsCode
# @Description:

import pandas as pd
import numpy as np
import matplotlib.pyplot as mplt

# 读取excel文件
r_file = pd.ExcelFile('student.xls')
# 读取excel文件中的sheet1
data = r_file.parse('Sheet1')
# 求各省的个数
pt_n = pd.pivot_table(data, index=['省份'], aggfunc=np.size)  # aggfunc=np.sum 求和，默认是平均值

mplt.rcParams['font.sans-serif'] = ['SimHei']
pt_n.plot(kind='bar')

# 修改
# index的倾斜角度
mplt.xticks(rotation=45)
mplt.title('各省数量')
mplt.xlabel('省份')
mplt.ylabel('个数')
mplt.legend()

mplt.show()
